import { Controller, Get, Post, Body, Headers } from '@nestjs/common';
import { ActionLogsService } from './action-logs.service';
import { ApiBody, ApiHeader, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { UserInfoDto } from '../model/dto/user-info.dto';
import { RecordActionLogDto } from './dto/record-action-log.dto';
import { UserActionLogDto } from './dto/user-action-log.dto';

@Controller('action-logs')
export class ActionLogsController {
  constructor(private readonly actionLogsService: ActionLogsService) {}

  @Post()
  @ApiOperation({ summary: '增加记录' })
  @ApiBody({ type: RecordActionLogDto })
  @ApiHeader({
    name: 'user',
    description: '用户信息，JSON字符串或用户ID等',
    required: true,
  })
  add(
    @Body() recordActionLogDto: RecordActionLogDto,
    @Headers('user') userDto: UserInfoDto,
  ) {
    return this.actionLogsService.add(
      recordActionLogDto,
      JSON.parse(userDto as unknown as string) as UserInfoDto,
    );
  }

  @Get()
  @ApiOperation({ summary: '查询记录' })
  @ApiResponse({
    status: 200,
    type: [UserActionLogDto],
  })
  @ApiHeader({
    name: 'user',
    description: '用户信息，JSON字符串或用户ID等',
    required: true,
  })
  findAll(@Headers('user') userDto: UserInfoDto) {
    return this.actionLogsService.findAll(
      JSON.parse(userDto as unknown as string) as UserInfoDto,
    );
  }

  // @Get(':id')
  // findOne(@Param('id') id: string) {
  //   return this.actionLogsService.findOne(+id);
  // }

  // @Patch(':id')
  // update(@Param('id') id: string, @Body() updateActionLogDto: UpdateActionLogDto) {
  //   return this.actionLogsService.update(+id, updateActionLogDto);
  // }

  // @Delete(':id')
  // remove(@Param('id') id: string) {
  //   return this.actionLogsService.remove(+id);
  // }
}
